package model

import (
	"database/sql"
	"gorm.io/gorm"
)

type PodEnv struct {
	BaseModel
	PodID    int64  `json:"pod_id"`
	EnvKey   string `json:"env_key"`
	EnvValue string `json:"env_value"`
}

// 在同一个事务中更新数据
func (p *PodEnv) AfterDelete(tx *gorm.DB) (err error) {
	if p.DeletedAt.Valid {
		tx.Exec("UPDATE pod_env SET is_deleted = @is_deleted where pod_id = @pod_id",
			sql.Named("is_deleted", true), sql.Named("pod_id", p.PodID))
	}
	return
}
